import { axios } from '../utils/http'

/**
 * @description 获取二维码key
 * @param { Number } timestamp - 防止接口缓存
 */
export const QRKey = () => {
  const params = {
    timestamp: new Date().getTime()
  }
  return axios.get('/login/qr/key', { params })
}

/**
 * @description 获取二维码图像
 * @param { Number } timestamp - 防止接口缓存
 * @param { Number } key - 二维码key
 * @param { Boolean } qrimg - 传入后会额外返回二维码图片 base64 编码
 */
export const QRImg = (key) => {
  const params = {
    timestamp: new Date().getTime(),
    key,
    qrimg: true
  }
  return axios.get('/login/qr/create', { params })
}

/**
 * @description 获取二维码状态
 * @param { Number } timestamp - 防止接口缓存
 * @param { Number } key - 二维码key
 */
export const QRCheck = (key) => {
  const params = {
    timestamp: new Date().getTime(),
    key
  }
  return axios.get('/login/qr/check', { params })
}

/**
 * @description 获取登录状态
 * @param { Number } timestamp - 防止接口缓存
 */
export const loginStatus = () => {
  const params = {
    timestamp: new Date().getTime()
  }
  return axios.get('/login/status', { params })
}

/**
 * @description 退出登录
 */
export const logout = () => {
  return axios.get('/logout')
}

/**
 * @description 登录后，获取账号信息
 * @param { Number } timestamp - 防止接口缓存
 */
export const accountInfo = () => {
  const params = {
    timestamp: new Date().getTime()
  }
  return axios.get('/user/account', { params })
}

/**
 * @description 登录后，获取用户信息
 * @param { Number } timestamp - 防止接口缓存
 * @param { Number } uid - 用户id
 */
export const userInfo = (uid) => {
  const params = {
    timestamp: new Date().getTime(),
    uid
  }
  return axios.get('/user/detail', { params })
}
